<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户管理</title>
    <link href="../resources/bootstrap/css/bootstrap.css" rel="stylesheet">
    <link href="../resources/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link href="../resources/css/style.css" rel="stylesheet">
    <link href="../resources/css/exam.css" rel="stylesheet">
    <script type="text/javascript" src="../resources/js/jquery/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="../resources/vue/vue.js"></script>
    <script type="text/javascript" src="../resources/vue/date.js"></script>
    <script type="text/javascript" src="../resources/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../resources/js/all.js"></script>
    <script type="text/javascript" src="../resources/js/tag-list.js"></script>
    <script type="text/javascript" src="../resources/js/add-tag.js"></script>
    <script type="text/javascript" src="../resources/js/add-tag.js"></script>
    <script type="text/javascript" src="../resources/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script type="text/javascript" src="../resources/laypage/laypage.js" charset="utf-8"></script>
    <script type="text/javascript" src="../resources/layui/layui.all.js" charset="utf-8"></script>
</head>
<body>
<header>
    <div class="logo">
        <h1>在线考试系统</h1>
    </div>
    <div class="navbar bs-docs-nav" role="banner">
        <div class="container" style="margin: 0  264px ;">
            <ul class="nav navbar-nav">
                <li class="nav-tabs">
                    <a href="main.html" style="font-size: 1.2em; width: 135px;"><i
                            class="glyphicon glyphicon-home"></i>&nbsp;首页</a>
                </li>
                <li>
                    <a href="/view/question/question-list" style="font-size: 1.2em;width: 132px;"><i
                            class="glyphicon glyphicon-list"></i>&nbsp;试题管理</a>
                </li>

                <li>
                    <a href="exampaper-list.html" style="font-size: 1.2em;width: 132px;"><i
                            class="glyphicon glyphicon-list-alt"></i>&nbsp;试卷管理</a>
                </li>
                <li>
                    <a href="exam-list.html" style="font-size: 1.2em;width: 132px;"><i
                            class="glyphicon glyphicon-indent-right"></i>&nbsp;考试管理</a>
                </li>
                <li class="nav-tabs">
                    <a href="/toUser.do" style="font-size: 1.2em;width: 130px;"><i
                            class="glyphicon glyphicon-user"></i>&nbsp;用户管理</a>
                </li>
                <li>
                    <a href="/toTag.do" style="font-size: 1.2em;width: 132px;"><i
                            class="glyphicon glyphicon-random"></i>&nbsp;通用管理</a>
                </li>
                <li>
                    <a href="/toSystem.do" style="font-size: 1.2em;width: 132px;"><i
                            class="glyphicon glyphicon-cog"></i>&nbsp;系统设置</a>
                </li>
            </ul>
            <a href="/userLogout" style="position: absolute;right: 100px; top: 10px;"><i class=""></i>[注销]</a>
        </div>

    </div>
</header>
<div id="exam-content-left" style="width: 150px; position: relative ;left: 220px;">
    <ul class="nav nav-pills nav-stacked" style="font-size: 1.1em; margin-top: 100px; text-align: right;">
        <li class="active">
            <a href="/toStudentList.do"> <i class="glyphicon glyphicon-user"></i> 用户管理 </a>
        </li>
        <li>
            <a href="/toTeacherList.do"> <i class="glyphicon glyphicon-globe"></i> 教师管理 </a>
        </li>
        <li>
            <a href="/toAdminList.do"> <i class="glyphicon glyphicon-fire"></i> 管理员管理 </a>
        </li>
    </ul>
</div>

<div class="container">
    <div class="col-xs-10" id="right-content">
        <div class="page-header"></div>
        <div id="app" class="container">
            <div id="question-list">
                <div id="field-list">
                    <div class="table-controller">
                        <button class="btn btn-default btn-sm" id="addUserBtn"style="font-size: 1.3em;">
                            <i class="fa fa-plus-square"></i> 添加用户
                        </button>
                        <button class="btn btn-default btn-sm" id="addUsers" style="font-size: 1.3em;">
                            <i class="fa fa-plus-square"></i> 批量新增
                        </button>
                    </div>
                    <form id="searchForm">
                        <div class="input-group search-form">
                            <input type="text" class="form-control" placeholder="用户名" id="userName"
                                   style="width: 100px;">&emsp;
                            <input type="text" class="form-control" placeholder="真实姓名" id="trueName"
                                   style="width: 100px;">&emsp;
                            <input type="text" class="form-control" placeholder="证件号" id="nationalId"
                                   style="width: 200px;">&emsp;
                            <input type="text" class="form-control" placeholder="手机号" id="phoneNum"
                                   style="width: 120px;">&emsp;
                            <input type="text" class="form-control" placeholder="班级" id="depName" style="width: 150px;">&emsp;
                            <span><label for="enabled">状态:</label>
                <select class="select" id="enabled" style="width: 100px;">
                    <option value="">全部</option>
                    <option value="1">正常</option>
                    <option value="0">禁用</option>
                </select>
            </span>&emsp;
                            <button class="btn btn-sm btn-info" type="button" id="btn-search">
                                <i class="fa fa-search"></i>搜索
                            </button>
                        </div>
                    </form>
                </div>
                <table class="table-striped table" align="center">
                    <thead>
                    <tr>
                        <td>序号</td>
                        <td>用户名</td>
                        <td>真实姓名</td>
                        <td>证件号</td>
                        <td>手机号</td>
                        <td>邮箱</td>
                        <td>创建时间</td>
                        <td>班级</td>
                        <td>状态</td>
                        <td>操作</td>
                    </tr>
                    </thead>
                    <tbody>
                    <tr class="active" v-for="(item,index) in result">
                        <td>{{index+1}}</td>
                        <td>{{item.userName}}</td>
                        <td>{{item.trueName}}</td>
                        <td>{{item.nationalId}}</td>
                        <td>{{item.phoneNum | StringFilter}}</td>
                        <td>{{item.email | StringFilter}}</td>
                        <td>{{item.createTime | DateFilter}}</td>
                        <td>{{item.department.depName}}</td>
                        <td>{{item.enabled | StateFilter}}</td>
                        <td>
                            <span class="r-reset-pwd-btn btn-sm btn-warning" @click="editPwd(item.userId)">密码</span>
                            <span class="r-update-btn btn-sm btn-info" @click="editInfo(item.userId)">资料</span>
                            <span class="r-update-btn btn-sm btn-danger" @click="editDisable(item.userId)">禁用/启用</span>
                        </td>
                    </tr>
                    </tbody>
                    <tr align="center">
                        <td colspan="11">
                            <div id="pagenav"></div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</div>

<footer>
    <div class="container" style="width: 500px; margin: 0 auto;">
        <div class="row">
            <div class="col-md-12">
                <div class="copy">
                    <p>
                        ExamManage © <a href="javascript:void(0);" target="_blank">ExamManage</a> - <a
                            href="javascript:void(0);" target="_blank">主页</a> | <a href="javascript:void(0);"
                                                                                   target="_blank">关于我们</a>
                        | <a href="javascript:void(0);" target="_blank">FAQ</a> | <a
                            href="javascript:void(0);" target="_blank">联系我们</a>
                    </p>
                </div>
            </div>
        </div>
    </div>
</footer>
</body>
</html>
<script>
    Vue.filter("DateFilter", function (date) {
        var v = new Date(date);
        return formatDate(v, "yyyy-MM-dd HH:mm:ss");
    });

    Vue.filter("StateFilter", function (state) {
        if (state == 1) {
            return "正常";
        } else {
            return "禁用";
        }
    });

    Vue.filter("StringFilter", function (str) {
        if (str == null) {
            return "无";
        } else {
            return str;
        }
    });

    var app = new Vue({
        el: "#app",
        data: {
            result: []
        }
    });

    var getUserByPage = function (curr) {
        $.ajax({
            type: 'POST',
            url: '/getAllUserByPage',
            dataType: 'json',
            data: {
                pageSize: 10,
                currPage: curr || 1,
                userName: $("#userName").val(),
                trueName: $("#trueName").val(),
                nationalId: $("#nationalId").val(),
                phoneNum: $("#phoneNum").val(),
                enabled: $("#enabled").val(),
                depName: $("#depName").val(),
                role:3
            },
            success: function (msg) {
                //console.log(msg);
                app.result = msg.page;
                laypage({
                    cont: 'pagenav',  //分页容器
                    pages: msg.totalPage, //总页数
                    skin: '#333333',
                    first: '第一页',
                    last: '最后一页',
                    curr: curr || 1,
                    jump: function (obj, first) {
                        if (!first) {
                            getUserByPage(obj.curr);
                        }
                    }
                });
            }
        });
    };

    getUserByPage();

    $("#btn-search").click(function () {
        getUserByPage();
    });

    $("#addUserBtn").click(function () {
        layer.open({
            type: 2,
            title: '添加用户',
            fix: false,
            maxmin: true,
            shadeClose: true,
            area: ['800px', '650px'],
            content: '/toAddUser?id=3',
            end: function () {
                getUserByPage();
            }
        });
    });
    $("#addUsers").click(function () {
        layer.open({
            type: 2,
            title: '批量新增',
            fix: false,
            maxmin: true,
            shadeClose: true,
            area: ['800px', '500px'],
            content: '/toFileUploadUser',
            end: function () {
                getUserByPage();
            }
        });
    });

    var editPwd = function (id) {
        layer.open({
            type: 2,
            title: '修改密码',
            fix: false,
            maxmin: true,
            shadeClose: true,
            area: ['300px', '250px'],
            content: '/editPwd?userId=' + id,
            end: function () {
                getUserByPage();
            }
        });
    };

    var editInfo = function (id) {
        layer.open({
            type: 2,
            title: '修改资料',
            fix: false,
            maxmin: true,
            shadeClose: true,
            area: ['800px', '650px'],
            content: '/editInfo?userId=' + id,
            end: function () {
                getUserByPage();
            }
        });
    };

    var editDisable = function (id) {
        layer.confirm('确认禁用/启用？', {
            btn: ['是', '否']
        }, function () {
            $.ajax({
                type: 'GET',
                dataType: 'JSON',
                url: '/doDisable',
                data: {
                    userId: id
                },
                success: function (data) {
                    if (data > 0) {
                        getUserByPage();
                        layer.msg('成功', {icon: 6});
                    } else {
                        layer.msg('失败', {icon: 2});
                    }
                }, error: function () {
                    //alert("异常");
                }
            });
        }, function () {

        });
    }
</script>